package com.tsunami.user.feign.fallback;

import com.tsunami.base.R;
import com.tsunami.exception.code.ExceptionCode;
import com.tsunami.user.feign.UserQuery;
import com.tsunami.user.feign.UserResolveApi;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @Classname UserResolveApiFallback
 * @Description TODO
 * @Date 2021-11-02 17:10
 * @Created by lx
 */
@Component
@Slf4j
public class UserResolveApiFallback implements FallbackFactory<UserResolveApi> {
    @Override
    public UserResolveApi create(Throwable throwable) {
        return new UserResolveApi() {
            /**
             * 根据id 查询用户详情
             *
             * @param id
             * @param userQuery
             * @return
             */
            @Override
            public R getById(Long id, UserQuery userQuery) {
                log.error("通过用户名查询用户异常:{}", id, throwable);
                return R.error().exCode(ExceptionCode.TIME_OUT);
            }
        };
    }
}
